[Xamarin.Android.Build.Tasks] Add XA1031 error for AndroidHttpClientHandlerType#7448
[Xamarin.Android.Build.Tasks] Add XA1031 error for AndroidHttpClientHandlerType#7448jonpryor merged 6 commits intodotnet:mainfrom
AndroidHttpClientHandlerType#7448Conversation
src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/EnvironmentContentTests.cs
Show resolved
Hide resolved
67e6a58 to
30264af
Compare
jonathanpeppers
left a comment
There was a problem hiding this comment.
The actual code changes look good. But maybe we should adjust some of the user-facing messages?
|
WIP commit message: [Xamarin.Android.Build.Tasks] Add XA1031 error (#7448)
Fixes: https://github.com/xamarin/xamarin-android/issues/7326
Commit d3e87674 added a requirement that, under .NET 6+, the
`$(AndroidHttpClientHandlerType)` MUST inherit from
[`System.Net.Http.HttpMessageHandler`][0]. This was unfortunately a
change from Classic, which allowed/required that
[`System.Net.Http.HttpClientHandler`][1] be the base class.
Allowing `HttpClientHandler` to be in the inheritance hierarchy for
`$(AndroidHttpClientHandlerType)` would result in a
`NullReferenceException` at runtime under .NET 6.
Commit d3e87674 contained a TODO:
> TODO: [Emit a build-time warning][2] if
> `$(AndroidHttpClientHandlerType)` is set to an invalid value
Implement this TODO: add a build-time check that verifies that
`$(AndroidHttpClientHandlerType)` is a valid type for the target,
e.g. is an `HttpMessageHandler` subclass on .NET 6.
If `$(AndroidHttpClientHandlerType)` is not a valid type, then an
XA1031 error is raised:
error XA1031: The 'AndroidHttpClientHandlerType' has an invalid value of '{0}' please check your project settings.
Additionally, if `$(AndroidHttpClientHandlerType)` is
`System.Net.Http.SocketsHttpHandler, System.Net.Http`, *and*
`$(UseNativeHttpHandler)` isn't set, then
set `$(UseNativeHttpHandler)` to false. This is necessary to ensure
that `SocketsHttpHandler` is preserved by the linker.
[0]: https://learn.microsoft.com/en-us/dotnet/api/system.net.http.httpmessagehandler?view=net-6.0
[1]: https://learn.microsoft.com/en-us/dotnet/api/system.net.http.httpclienthandler?view=net-6.0
[2]: https://github.com/xamarin/xamarin-android/issues/7326 |
25c0027 to
d4115ab
Compare
54e00f8 to
4fb4ac1
Compare
| <HttpActivityPropagationSupport Condition="'$(HttpActivityPropagationSupport)' == ''">false</HttpActivityPropagationSupport> | ||
| <InvariantGlobalization Condition="'$(InvariantGlobalization)' == ''">false</InvariantGlobalization> | ||
| <StartupHookSupport Condition="'$(StartupHookSupport)' == ''">false</StartupHookSupport> | ||
| <UseNativeHttpHandler Condition=" $(AndroidHttpClientHandlerType.Contains ('System.Net.Http.SocketsHttpHandler')) And '$(UseNativeHttpHandler)' == '' ">false</UseNativeHttpHandler> |
There was a problem hiding this comment.
@dellis1972 : this feels like something that should be called out in the commit message. What's the rationale here?
There was a problem hiding this comment.
I think this is left over. But we got info from the runtime team that if a user defines System.Net.Http.SocketsHttpHandler' as the handler type they MUST use set the UseNativeHttpHandler msbuild property. Otherwise it doesn't work.
This is where the conversaton took place https://discord.com/channels/732297728826277939/732297837953679412/1029777522897993748
There was a problem hiding this comment.
Should we remove it ("this is left over") or keep it ("extract rationale from Discord")?
src/Xamarin.Android.Build.Tasks/Tasks/CheckClientHandlerType.cs
Outdated
Show resolved
Hide resolved
fbf3e92 to
cf82b02
Compare
cf82b02 to
2d0ce97
Compare
…HandlerType` Fixes dotnet#7326 We should check the value of the `AndroidHttpClientHandlerType` property during the build process. This property can have a number of different values depending on what version of Xamarin.Android is being used. Under Classic a valid value is `Xamarin.Android.Net.AndroidClientHandler`, however under .NET 6+ the valid values are - `Xamarin.Android.Net.AndroidMessageHandler`. - `System.Net.Http.SocketsHttpHandler, System.Net.Http`. We should raise an error if the user is using an invalid value.
* main: [Xamarin.Android.Build.Tasks] use %(TrimmerRootAssembly.RootMode) All (dotnet#7651) Bump to dotnet/installer@47a747f 8.0.100-alpha.1.22616.7 (dotnet#7647) Bump to dotnet/installer@167a4ed 8.0.100-alpha.1.22611.1 (dotnet#7630) Bump to xamarin/Java.Interop/main@f8d77fa (dotnet#7638) [ci] Fix Designer test paths (dotnet#7635) [Xamarin.Android.Build.Tasks] perf improvements for LlvmIrGenerator (dotnet#7626) [Xamarin.Android.Build.Tasks] AutoImport `*.webp` files (dotnet#7601) Localized file check-in by OneLocBuild Task (dotnet#7632) Bump $(ProductVersion) to 13.2.99 Bump to xamarin/monodroid@c0c933b7 (dotnet#7633) [Xamarin.Android.Build.Tasks] Fix aapt_rules.txt corruption (dotnet#7587) [Xamarin.Android.Build.Tasks] Add XA1031 error (dotnet#7448) Bump to xamarin/Java.Interop/main@149d70f (dotnet#7625) [CODEOWNERS] More updates to CODEOWNERS (dotnet#7628) [Xamarin.Android.Build.Tasks] avoid `File.Exists()` check (dotnet#7621)
Fixes #7326
We should check the value of the
AndroidHttpClientHandlerTypeproperty during the build process. This property can have a number of different values depending on what version of Xamarin.Android is being used.Under Classic a valid value is
Xamarin.Android.Net.AndroidClientHandler, however under .NET 6+ the valid values areXamarin.Android.Net.AndroidMessageHandler.System.Net.Http.SocketsHttpHandler, System.Net.Http.We should raise an error if the user is using an invalid value.